package com.kob.backend.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 管理文件下载
 * 前端请求url：http://localhost:3000/file/文件名.后缀
 */
@Configuration
public class FileConfig implements WebMvcConfigurer {

    @Value(value = "${root.file.path}")
    private String rootFilePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/file/**").addResourceLocations("file:"+ rootFilePath);
    }
}
